package com.ias.agdis_r.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.ias.agdis_r.R;
import com.ias.agdis_r.module.MessageModel;
import com.ias.agdis_r.util.S;

import java.util.ArrayList;
import java.util.HashMap;

/**
 * Created by guoxr on 2015/9/16.
 */
public class TaskDocListAdapter extends BaseAdapter {

    private int selectItem = -1;
    private Context context;
    private LayoutInflater inflater = null;
    private ArrayList<HashMap<String, Object>> mylist;

    public TaskDocListAdapter(Context context, ArrayList<HashMap<String, Object>> list) {
        this.context = context;
        this.mylist = list;
    }

    private class ViewHolder {
        TextView txt_DNM, txt_BNO, txt_STATE;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = new ViewHolder();
        if (null == convertView) {
            inflater = LayoutInflater.from(context);
            convertView = inflater.inflate(R.layout.item_taskdoclist, null);
            holder.txt_DNM = (TextView) convertView.findViewById(R.id.txt_DNM);
            holder.txt_BNO = (TextView) convertView.findViewById(R.id.txt_BNO);
            holder.txt_STATE = (TextView) convertView.findViewById(R.id.txt_STATE);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        if (mylist != null && mylist.size() > 0) {
            holder.txt_DNM.setText(mylist.get(position).get(MessageModel.DNM).toString());
            holder.txt_BNO.setText(mylist.get(position).get(MessageModel.BNO).toString());
            holder.txt_STATE.setText(mylist.get(position).get(MessageModel.STS).toString());
        }
        if (position == selectItem) {
            convertView.setBackgroundColor(Color.CYAN);
        } else {
            convertView.setBackgroundColor(Color.TRANSPARENT);
        }
        return convertView;
    }

    public void setSelectItem(int selectItem) {
        this.selectItem = selectItem;
    }

    @Override
    public int getCount() {
        return mylist.size();
    }

    @Override
    public Object getItem(int position) {
        return mylist.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
}
